home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group03a.txt
/
000072_icon-group-sender_Tue Apr 15 07:46:16 2003.msg
< prev
next >
Wrap
Internet Message Format
|
2003-12-22
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h3FEjAM04078
for icon-group-addresses; Tue, 15 Apr 2003 07:45:10 -0700 (MST)
Message-Id: <200304151445.h3FEjAM04078@baskerville.CS.Arizona.EDU>
From: Richard Bos <rlb@hoekstra-uitgeverij.nl>
X-Newsgroups: comp.lang.icon
Subject: Re: Simplifying Integer Arithmetic
User-Agent: MT-NewsWatcher/3.1 (PPC)
Date: Tue, 15 Apr 2003 12:22:39 +0200
X-Complaints-To: abuse@nl.uu.net
To: icon-group@cs.arizona.edu
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
In article <b33380$e1o$0@205.153.154.199>,
Patrick Scheible <kkt@itchy.serv.net> wrote:
> "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> writes:
>
> > The question I pose to this group is whether we should assume that any C
> > compiler used for Icon uses the "round towards 0" method for evaluating a /
> > b and a % b for integers a and b. Given this assumption, we could simplify
> > the div3 and mod3 functions in "runtime/rmisc.r" as follows:
>
> I would suggest not making any assumptions about which C compilers
> people may use at some point, especially since the work of making Icon
> round towards 0 regardless of the C compiler's behavior has already
> been done. Who knows what strange platforms someone may wish to port
> Icon to at some point?
>
> However, I have not done a survey of whether there are any C compilers
> that do not round towards 0. (Maybe the nice people in comp.lang.c
> happen to know?)
Right. I'm a bit late answering this (only just set up the test Mac with
ProIcon and Newswatcher on it), and I'm not really a c.l.c regular
anymore, but it's like this:
In the first C Standard of 1989, positive/positive division rounded
towards zero (obviously), and +/+ modulo is positive. However, if either
operand is negative, the direction of the rounding as well as the sign
of the modulo is implementation-defined. Even so, for all
implementations, (a/b)*a + a%b must equal a, as long as a/b can be
represented at all.
In the new Standard of 1999, this is more closely regulated: all
implementations that use the new Standard _must_ truncate towards zero.
This also means that the result of the modulo operator has the same sign
as its first operand.
I haven't got a large selection of compilers myself, but those I do have
all round towards zero.
Richard